package willispace;

import entities.Entity;
import entities.Tile;
import java.awt.Image;
import java.awt.Point;

/**
 * Map Class
 * Defines tiles for current map
 * @author mateusz
 */
public class Map {

    private Tile[][] map;
    
    /**
     * Creates new map with specified width and height
     * @param width     width of map
     * @param height    height of map
     */
    public Map( int width, int height ) {
        map = new Tile[ height ][ width ];
    }

    /**
     * Sets tile with coordinates (x,y)
     * <pre>
        (0,0)      x
        ---------->
        |
        |
       y|
        \/
     * </pre>
     * 
     * @param x             X (horizontal) index of tile (counting from 0)
     * @param y             Y (vertical) index of tile (counting from 0)
     * @param blocked       if tile is blocked (e.g. there is a rock on it)
     * @param background    image with background for tile
     * @param relatedEntity related entity with this tile (can be changed later)
     */
    public void setTile( int x, int y, Boolean blocked, Image background, Entity relatedEntity) {
        map[y][x] = new Tile( new Point( x, y ), blocked, background, relatedEntity);
    }

    /**
     * See {@link #setTile(int, int, java.lang.Boolean, java.awt.Image, entities.Entity)}
     */
    public void setTile( int x, int y, Boolean blocked, Image background) {
        setTile(x, y, blocked, background, null);
    }
    
    /**
     * Returns width of map
     * @return width of map
     */
    public int getWidth(){
        return map[0].length;
    }
    
    /**
     * Returns height of map
     * @return height of map
     */
    public int getHeight(){
        return map.length;
    }
    
    /**
     * Returns tile with indexes (x,y)
     * @param x     horizontal index (counting from 0)
     * @param y     vertical index (counting from 0)
     * @return      {@link Tile Tile} with indexes [y][x]
     * @see Tile
     */
    public Tile getTile(int x, int y){
        return map[y][x];
    }
}
